package com.fs.base.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import com.fs.base.pojo.User;
/**
 * @author TiddlerCJ
 */
public interface UserRepository extends JpaRepository<User,String>, JpaSpecificationExecutor<User>{

	User findByAccountAndPwd(String account,String pwd);
	
	User findByEmailAndPwd(String email,String pwd);
	
	User findByAccount(String account);
	
	User findByEmail(String email);
	
	User findByEmailAndAccountType(String email,String accountType);
	
	/**
	 * 通过账号查询其组织领导
	 * @param account
	 * @return
	 */
	//@Transactional
	//@Query(value = "SELECT org_leader FROM s_org o WHERE o.org_no  = (SELECT org_no FROM s_user u WHERE u.account =?1 LIMIT 1  )",nativeQuery = true)
	//String findUserIdByMyOrgLeader(String account);
	
	/**
	 * 修改密码
	 */
	@Transactional
	@Modifying
	@Query(value = "update s_user s set s.pwd = ?1 where s.id = ?2",nativeQuery = true)
	void updatePwdById(String pwd,String userId);
	
	@Transactional
	@Modifying
	@Query(value = "update s_user s set s.status = ?1 where s.id = ?2",nativeQuery = true)
	void updateStatus(String status,String userId);
	
}
